package com.demo.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.Date;

@Slf4j
@EnableBinding(value ={OrderOutputChannelProcessor.class})
public class SmsProducer {
    @Autowired
    private OrderOutputChannelProcessor channel;

    public void sendMsg(String msg) {
        channel.saveOrderOutput().send(MessageBuilder.withPayload(msg)
                .setHeader("x-delay", 5 * 1000)
                .build());
        log.info("开始时间{}，消息发送成功：{}",new Date(),msg);
    }

}
